package com.tshopping.util;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
 * @name: EmailSender
 * @description: 发送邮箱类
 * @author: Jackeys
 * @date: 2020-12-15 15:31
 */
public class EmailSender {

    public static boolean sendEmail(String email,String content) throws MessagingException {
        Properties properties=new Properties();
        properties.put("mail.transport.protocol", "smtp");
        properties.put("mail.smtp.host", "smtp.qq.com");
        properties.put("mail.smtp.port", 465);
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.ssl.enable", "true");
        Session session = Session.getInstance(properties);
        session.setDebug(true);
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("1623427947@qq.com"));
        InternetAddress to = new InternetAddress(email);
        message.setRecipient(MimeMessage.RecipientType.TO, to);
        message.setSubject("TBlog");
        message.setText(content);
        Transport transport = session.getTransport();
        transport.connect("1623427947@qq.com", "etsjqfxqtbjmdhjh");
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
        return true;
    }
    public static String getSecurityCode(int cnt) {
        int multiple=1;
        for(int i=0;i<cnt-1;i++){
            multiple*=10;
        }
        int newNum = (int)((Math.random()*9+1)*multiple);
        return String.valueOf(newNum);
    }

}
